package com.benshou.bcss.common.j17common;

import com.benshou.bcss.common.j17common.annotation.Nullable;
import lombok.NonNull;

import java.util.Collection;

/**
 * @author <a href="mailto:wh1zper@qq.com">wh1zper</a>
 */
public interface Identifiable<T> {

    T identification();

    @Nullable
    static <T, R extends Identifiable<? extends T>> R findByIdentification(
            Collection<? extends R> identifiableList,
            @NonNull T identification) {
        if (identifiableList == null || identifiableList.isEmpty()) {
            return null;
        }

        for (R identifiable : identifiableList) {
            if (identification.equals(identifiable.identification())) {
                return identifiable;
            }
        }

        return null;
    }
}
